<?php
/**
 * Project 模型类
 * 
 */

class Project_model extends CI_Model {
    
    public function __construct()
    {
         $this->load->database();
    }

    // 创建项目
    public function createProject() {

    }





    public function editProject($pid) {
        
    }

    public function deleteProject($pid) {
        
    }

    public function seeProject($pid) {
        
    }



























    // 获取表中的记录总数
    public function record_count()
    {
        return $this->db->count_all("article");
    }

    // 获取单篇文章
    public function get_one($id)
    {
        $query = $this->db->get_where('article', array('id'=>$id));
        return $query->row_array();
    }

    // 获取多篇文章(指定页码的)
    public function get_all($limit, $page)
    {
        $this->db->order_by('id', 'desc');
        $query = $this->db->get("article", $limit, ($page-1)*$limit);
        
        if ($query->num_rows() > 0)
        {
            return $query->result_array();
        }

        return array();
    }

    // 添加数据
    public function add_article()
    {
        $this->load->helper('url');

        $data = array(
            'cat_id' => '',
            'user_id' => '',
            'art_title' => $this->input->post('art_title'),
            'art_content' => $this->input->post('art_content'),
            'status' => 1,
            'post_date' => date('Y-m-d H:i:s'),
            'art_author' => $this->input->post('art_author'),
            'click' => 0
        );

        return $this->db->insert('article', $data);
    }

}